package com.easy.user.service;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.easy.common.bean.SysPermission;
import com.easy.common.service.IPermissionService;
import com.easy.user.mapper.PermissionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PermissionService extends ServiceImpl<PermissionMapper,SysPermission> implements IPermissionService {
    @Autowired
    PermissionMapper permissionMapper;
    @Override
    public SysPermission insert(SysPermission permission) {
        permissionMapper.insert(permission);
        SysPermission result=this.getByID(permission.getId());
        return result;
    }

    @Override
    public SysPermission update(SysPermission permission) {
        permissionMapper.updateById(permission);
        SysPermission result=this.getByID(permission.getId());
        return result;
    }

    @Override
    public int delete(Integer id) {
        int num=permissionMapper.deleteById(id);
        return num;
    }

    @Override
    public SysPermission getByID(Integer id) {
        SysPermission result=permissionMapper.selectById(id);
        return result;
    }

    @Override
    public IPage<SysPermission> getListByPage(IPage page, SysPermission permission) {

        Wrapper wrapper=new QueryWrapper(permission);
        IPage result=permissionMapper.selectPage(page,wrapper);
        return result;
    }

    @Override
    public List<SysPermission> getList(SysPermission permission) {
        Wrapper wrapper=new QueryWrapper(permission);
        List<SysPermission> result=permissionMapper.selectList(wrapper);
        return result;
    }

}
